package com.zerox.service.impl;

import com.zerox.entity.Supplier;
import com.zerox.entity.SysUser;
import com.zerox.mapper.SysUserMapper;
import com.zerox.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser login(String username, String password) {
       SysUser sysUser = sysUserMapper.login(username,password);

        if (sysUser == null) {
            return null;
        }

        if (password.equals(sysUser.getPassword())) {
            return sysUser;
        }
        return null;
    }

    @Override
    public List<SysUser> list(Integer pageNo, Integer pageSize,String realName,Integer roleId) {
        Integer startIndex= (pageNo-1)* pageSize;
        return sysUserMapper.list(startIndex,pageSize,realName,roleId);
    }

    @Override
    public SysUser selectUser(Integer id) {
        return sysUserMapper.selectUser(id);
    }

    @Override
    public int count(String realName, Integer roleId) {
        return sysUserMapper.count(realName,roleId);
    }

    @Override
    public int update(SysUser sysUser) {
        return sysUserMapper.update(sysUser);
    }

    @Override
    public List<Supplier> listSupplier(Integer pageNo, Integer pageSize, String supName) {
        Integer startIndex= (pageNo-1)* pageSize;
        return sysUserMapper.listSuppliers(startIndex,pageSize,supName);
    }

    @Override
    public int count2(String supName) {
        return sysUserMapper.count2(supName);
    }

    @Override
    public int add(SysUser sysUser) {
        return sysUserMapper.add(sysUser);
    }

    @Override
    public int userByAccount(String account) {
        return sysUserMapper.userByAccount(account);
    }

    @Override
    public int delete(Integer id) {
        return sysUserMapper.delete(id);
    }

    @Override
    public Supplier selectById(Integer id) {
        return sysUserMapper.SupplierselectById(id);
    }

    @Override
    public int supplierAdd(Supplier supplier) {
        return sysUserMapper.supplierAdd(supplier);
    }

    @Override
    public int supplierDelete(Integer id) {
        return sysUserMapper.supplierDelete(id);
    }

    @Override
    public int supplierUpdate(Supplier supplier) {
        return sysUserMapper.supplierUpdate(supplier);
    }

    @Override
    public Supplier selectBySupplierName(String supCode) {
        return sysUserMapper.supplierBySupCode(supCode);
    }


}
